//首页轮播图
var mySwiper = new Swiper('.swiper-container', {
    loop: true, // 循环模式选项
    // 自动轮播
    autoplay: true,
    // 如果需要分页器
    pagination: {
        el: '.swiper-pagination',
        // 点击可以进行焦点轮播
        clickable: true
    },

    //淡入淡出效果
    effect: 'fade',
    fadeEffect: {
        crossFade: true,
    }

})
//首页轮播图结束


//首页轮播图右侧公告切换
$('.notice-title .tab-head').mouseover(function () {
    $(this).addClass('on').siblings().removeClass('on');
    var index = $(this).index();
    $($('.con ul')[index]).css('display', 'block').siblings().css('display', 'none')
})


// 好货汇聚轮播渲染
function banner(obj) {
    var bannerDate = '';
    for (var i = 0; i < obj.length; i++) {
        bannerDate += `
    <li>
        <div class="p-img">
            <a href="goods-info.html?${obj[i].goods_id}">
                <img src="${obj[i].goods_thumb}" alt="">
            </a>
        </div>
        <div class="p-name">
            <a href="goods-info.html?${obj[i].goods_id}">${obj[i].title}</a>
        </div>
        <div class="p-price">
            <span class="shop-price">${obj[i].shop_price_formated}</span>
            <span class="original-price">${obj[i].market_price_formated}</span>
        </div>
    </li>`
    }
    bannerDate += bannerDate
    $('.tempWrap ul').html(bannerDate);
}
banner(allData.indexData.slideshowDate);



$('.tempWrap').hover(function () {
    clearInterval(temp.time);
    $('.prev , .next').css('display', 'block');
}, function () {
    $('.prev , .next').css('display', 'none');
    temp();
})
var img = 0;
$('.next').click(function () {
    img++;
    if (img == 7) {
        $('.tempWrap ul').css('left', '0');
        img = 1;
    }
    var targer = img * -238;
    moveAnimation2($('.tempWrap ul')[0], targer);
})
$('.prev').click(function () {
    img--;
    if (img == -1) {
        img = 5;
        $('.tempWrap ul').css('left', '-1904px');
    }
    var targer = img * -238;
    moveAnimation2($('.tempWrap ul')[0], targer);
})

function temp() {
    temp.time = setInterval(function () {
        $('.next').click();
    }, 5000)
}
temp();

//还没逛够渲染
function guessyoulikeShow(obj) {
    var guessData = '';
    for (var i = 0; i < obj.length; i++) {
        guessData += `<li>
        <a href="goods-info.html?${obj[i].goods_id}">
            <div class="p-img fs14">
                <img src="${obj[i].goods_thumb[0]}" alt="">
            </div>
            <div class="p-name">${obj[i].title}</div>
            <div class="p-price">
                <div class="shop-price">${obj[i].shop_price_formated}</div>
                <div class="original-price fs12">${obj[i].market_price_formated}</div>
            </div>
        </a>
    </li>`
    }
    $('.guessyoulike ul').html(guessData);
}
guessyoulikeShow(allData.indexData.mianDate);




// 跳楼效果点击事件
$('.lift-list .floor:lt(8)').click(function () {
    var index = $(this).index('.lift-list .floor');
    $('html').animate({
        scrollTop: $($('.jump')[index]).offset().top
    }, 300);
});




var mainOffsetTop = $('.index-festival-adv').offset().top;
$(window).scroll(function () {
    if ($(window).scrollTop() >= mainOffsetTop) {
        $('.lift-list').fadeIn(600);
    } else {
        $('.lift-list').fadeOut(600);
    };
    $('.jump').each(function (index, value) {
        if ($(window).scrollTop() >= value.offsetTop) {
            $('.floor').eq(index).addClass('on').siblings().removeClass('on');
        }
    })
});



$('.back-top').click(function () {
    $('html').animate({
        scrollTop: 0
    }, 1000);
});


function goodsinfo(){
    var goodsnum = $('#goodssum').text()
    localStorage.setItem('goodsnum' , goodsnum)
    var goodspri = $('#allgoodspri').text()
    localStorage.setItem('goodspri' , goodspri)
}
goodsinfo()
$('.count-add').click(function(){
    goodsinfo()
})

$('.count-remove').click(function(){
    goodsinfo()
})

$('.delete_cart').click(function(){
    goodsinfo()
})
$('.del').click(function (){
    goodsinfo()
})
$('.addbtn').click(function (){
    goodsinfo()
})
$('.subtr').click(function (){
    goodsinfo()
})